﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using SaladBar.Service.Services.Users;
using SaladBar.Domain.Users;
using SaladBar.Domain;

namespace SaladBar.AppCode.Security
{
    public class SaladBarProfileProvider : ProfileProvider
    {
        private UserService _UserService;

        public SaladBarProfileProvider(UserService userService)
        {
            this._UserService = userService;
        }
        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //return this._UserService.DeleteInactiveUsers(authenticationOption, userInactiveSinceDate, this.ApplicationName);
        }

        public override int DeleteProfiles(string[] usernames)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //return this._UserService.DeleteProfiles(usernames, this.ApplicationName);
        }

        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //return this._UserService.DeleteProfiles(profiles, this.ApplicationName);
        }

        public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //PagedQueryResult <User> users = this._UserService.FindInactiveProfilesByUserName(authenticationOption, usernameToMatch, userInactiveSinceDate, pageIndex - 1, pageSize, this.ApplicationName);
            //totalRecords = users.TotalCount;

            //ProfileInfoCollection profiles = new ProfileInfoCollection();

            //foreach (User user in users)
            //{
            //    ProfileInfo profile = new ProfileInfo(user.Username, !user.Profile.IsAuthenticatedProfile, user.LastActivityDate, user.UpdateDate, user.Profile.ProfileValues.Count);
            //    profiles.Add(profile);
            //}

            //return profiles;
        }

        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //PagedQueryResult<User> users = this._UserService.FindProfilesByUserName(authenticationOption, usernameToMatch, pageIndex - 1, pageSize, this.ApplicationName);
            //totalRecords = users.TotalCount;

            //ProfileInfoCollection profiles = new ProfileInfoCollection();

            //foreach (User user in users)
            //{
            //    ProfileInfo profile = new ProfileInfo(user.Username, !user.Profile.IsAuthenticatedProfile, user.LastActivityDate, user.UpdateDate, user.Profile.ProfileValues.Count);
            //    profiles.Add(profile);
            //}

            //return profiles;
        }

        public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //PagedQueryResult<User> users = this._UserService.GetAllInactiveProfiles(authenticationOption, userInactiveSinceDate, pageIndex - 1, pageSize, this.ApplicationName);
            //totalRecords = users.TotalCount;

            //ProfileInfoCollection profiles = new ProfileInfoCollection();

            //foreach (User user in users)
            //{
            //    ProfileInfo profile = new ProfileInfo(user.Username, !user.Profile.IsAuthenticatedProfile, user.LastActivityDate, user.UpdateDate, user.Profile.ProfileValues.Count);
            //    profiles.Add(profile);
            //}

            //return profiles;
        }

        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
            
            //this won't work because there won't be a user object associated with anonymous users
            //PagedQueryResult<User> users = this._UserService.GetAllProfiles(authenticationOption, pageIndex - 1, pageSize, this.ApplicationName);
            //totalRecords = users.TotalCount;

            //ProfileInfoCollection profiles = new ProfileInfoCollection();

            //foreach (User user in users)
            //{
            //    ProfileInfo profile = new ProfileInfo(user.Username, !user.Profile.IsAuthenticatedProfile, user.LastActivityDate, user.UpdateDate, user.Profile.ProfileValues.Count);
            //    profiles.Add(profile);
            //}

            //return profiles;
        }

        public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new NotImplementedException();

            //this won't work because there won't be a user object associated with anonymous users
            //return this._UserService.GetNumberOfInactiveProfiles(authenticationOption, userInactiveSinceDate, this.ApplicationName);
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            throw new NotImplementedException();
        }

        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            throw new NotImplementedException();
        }
    }
}